Big code cleanup and good progress to solve #12 and #13