refactors based on @luolong comments