Reinfinzing that main loop
Basic error handling