Massive code improvements. Added tag upgrading.