Updated code with a few bugfixes