Replaced magic numbers with vars or consts
improved variables names and code layout