Changed magic numbers with constants, improved code.