some final touches. Forked from here.