finish main logic
finish function
fixed bugs of javascript