Code cleanup.
Added flip feature and cleaned up more code.