Fix coding style and other issues pointed at #1239
Add more tests and refactors previous require test