Clean up and fixed bug #17