Made remove slightly more efficient and removed extra code in main