Code rewrite. Should be faster, added piano hooks