Refactor and fix delete bug

Closes #27