Made the smallest logic a function