refactored into objects
compiles without warnings