Fix bug and cleanup