Clean up and bug fixing