Splitted main in seperate functions for better
overview/error-control #3