Move everything into a single file

This makes it convenient for using as a standalone script.