some changes and bug fixes

made table flip more efficient