Convert int to NSInteger for consistent typing
Fix some types and casting