working on synchronous version