Cleanup and refined some codes.