Cleaned the code and set internal functions private