moved logic to appropriate pages