Added background remove algorithm and some refactoring.