output size adjustment

also some minor optimization