Fixed some compilation bugs, memory leaks and removed spaces