Fix the blatant bug in modules.service and do some code cleanup