code cleanup and adding specs