cleaning up code, added cap option