Better tag handling

This is for #5 and #12.