Moved main function in to two function for unit testing