Remove magic constants
Add null checks