Adding nearly-finished logic from Eclipse.