Fixed errors, added some functions implementations