made functions capable of being refactored, added more story to main code