made changes suggested by @nbeloglazov