refactor draw elements frame calculation