Wrote part of apply code