fixed null pointer & merged new code from master