Huge improvements to code, added devise support