Added new features, rewrite with regexp