Resolved some code design flaws