Fix a bug, todo clean this up