Improve the code for laybrinth