Added functions, removed magic numbers