Added CodeBuilder to simplify code generation

Changed methods and objects to use it too.