Bug fixes for subs