Refactor code that includes module check