Code and tests

Done for now.