seperated render prep and render post from if window open logic
Added comments into code and refactored for clarity