revise layout algorithm