Reimplemented everything to use states