Fixing some refactor bugs