fixed a few NPEs, bugs