basic function completed, bug fixed