added ApplicationStateManager + various fixes