Magic Number Removal and Function Implementation

Removed some magic numbers and implemented some functions.