Updates of code for neatness

Adding lower level functions in increase testability