code style changed
added additional checks for function return values