Fixed some type inference problems.
Added tagging support