Style fixes and error handling