refactor grid drawing into seperate function