Added controls, maybe fixed some memory misallocations, probably introduced some bugs...