Refactored code into more functions

Signed-off-by: retep998 <retep998@verizon.net>