Some cleanups, removed duplicated code.