Splitted main function into even smaller chunks