Still need to write proper test cases but I think it works!