Revamped, attempt to pass prime testcases