Improve module logic and error handling.