nullpointer check + fixed bug in switching perspective