Bug that cause the program to fail sometimes fixe. Code commented and refactored