crazy amount of logging and error handling