changed program structure for proper unit testing