Code cleanup, unify api