improve formatting and simplify code