Split out output code, fixed resolving represenation code, fixed a lot of warnings