Adding test cases and making alogorithm details common for test and ui