tried to make robust against orientation change