Several improvements. Still there are bugs