Seperated filter source

Moved filter implementation into seperate source file. Created helper
function to ease up the main function.