Cleanup, use g.resource and g.createLink instead of manually constructing URLs (also makes generated URLs valid), and add javadoc

x