tested and almost working