Cleaned up some mess and added Javadocs.