cleaned up and fixed a crash