Add new test, fix removing, reorganize some duplicate code