Improved code for handling resizes, solving issues with map disappearing randomly