fixed some functios and logic