Added devmode flag, refactoed controller