refactor and add manual test