simplify code and remove trailing spaces