Add more documentation and cleanup