Modernize and fix some bugs