Optimisation, bug fix and windows support