Code refactoring (moving import ctypes to be used only when needed)