Corrected errors causes by previous commit and fixes all buggs