Added for and fixed some bugs. I think it works now.