Code cleanup and integration of the cleanup expired function.