fixed migration and cleaned up code