Fixed errors and added functionality