rewrote most of functions added some new ones