more optimization and demo function work