Bug Fix and stability improvements

I fixed the bug that was there on the last commit and made the program
more stable.