Refactor character box and map rendering algorithm