refactor as suggested by @guewen