fixed the codes according to comments, still working on it