Initial attempt to fix bugs