fixed #448
Added some logging
reformatted some code
Fixed #449: avoid clearing cache at refresh