Commented everything, cleaned up some magic numbers.