if (result == FAILED)
// do whatever
You don't need the "else"! If the "if" statement evaluated to be true, then there's no reason why it would jump out of it. Therefore, there's no reason that the //do whatever part of the code should be inset! Do this a couple times, and you'll have a nightmare of nested code. Keep your code as shallow as possible. Don't nest if you don't have to.