bugfixes
first working version, with some console warnings to fix