Removed vertical space, added exception handling
Replaced str with string_types