Fixed internal bugs