refactored and moved most php to route file