Added sequence mode and cleaned up code.