messy server side code, don't bother yourself to understand what and how it does