Fixed several errors, seems to work well now