Fixed bugs in prefix method