Cleaned up code and fixed reset.