Major bug fix and redesign