Added most of the mode logic. It's broke right now though