Simplify code
Fix bug