Huge commit before rewriting code, added various tests