Fixed a few bugs and design flaws