Updated Database stuff. Also refactor. Untidy commit