changed tabs to spaces and fixed bugs