Fixed problem with multiple entries being written to the states collection
Added null promise check