minor refactors, added some error-handling/logging to console