fixed some bugs and improved python syntax