fixed bug with error bars; fixed a memory leak; reorganized