refactored as per todds suggestion extracted methods and few renaming