Bug fixes and pattern improvements