Updated fully working code for the core functionality. Email still needs work