some smaller changes and generalizations and some crazy java stuff