lots of bug fixes and fixing layout