BLUE: used less if's and narrowed the code to a minimum
for better work and easy to understand