General bugfixes and console.log calls for debugging