Small fixes
rewrote to use functions