Improved error handling. Added condition
Whitespace fix