Much better design and some fixes