Divided the code in small understandable parts