continued refactoring and added some documentation