bugfixes to P1. P2 newly added