Fixed some weird bug with the code

Weird bugs are fixed