refactor of mainly sy/unit.rb