Added a function and some weird loop