Fixed small bug in stored proc