Fixed a bug that caused a Seg Fault, commented the code properly, ready for testing on eres