Clean up code to be more readable
Added API support for capsules