Added specs and fixed various bugs