bugfix and code tested working