working code!!! somewhat