Cleaned up code and added better support for requiring non-JS modules