fixed few issues todo: needs optimazation