Fixed tests and cleaned up more code