Removed unused code. Turned all magic numbers to constants. Polished code a bit.