moved some code out of main() and into the constructor