Fixes race condition but needs refactor