major bug fixes & code improvments