prettified code and refactored parse_type()