Implement delete behaviour and refactor code.

Fixes #12