Cleaned up and fixed bug