fixed code based on comments