basic fuction working but requires debugging!!!