Use macros for magic constants
Remove unused code