added some null pointer checks if there are no flags