added alternative implementation without callback