Made code more efficient and a lot ligher.
Fixed some bugs.