better window dimension handling and minor env fix