Refactoring

Removed copy&paste and added converters. Moved magic numbers to
constants