Code cleanup and more precise use of c-interface