Added bunch of tests and fixed issues