first fully functional version

still need optimisation