FIXED: some bugs due to NULL pointers or 0 values