Fixing formatting and exception handling