Refactored, bugfixed, optimized tests