cleaned up and fixed bug