optimising & fix bugs