Properly encode IMPLICIT tag

Add tests for IMPLICIT and EXPLICIT tags with submodel and fix broken code.