Clean code; add tests