Refactor types and specs