Cleaned up the resetting code a bit