Removed ternery for isset
Tidy up and error handler in separate class