Clean-up

Removed unnecessary code, optimized SQL and Javascript