refactor module detection