Made some fix and cleaner code