Solved bugs preventing function