almost done with script, still doesn't work well though