Bug fixing and vectorizing