Cleaned up code, added cases