some modifications to make it more rpyhton compatible