Revert "intermediate commit"

This reverts commit d49c54c9038e0140e25a0fea6e330f0f883c3f89.
Fixed a few bugs